package ru.tpu.osu.faces.dao;

import java.io.Serializable;

import javax.persistence.*;

@Entity
public class Administrator implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8780841616092587365L;
	@Id
	private String login;
	
	public String getLogin() {
		return login;
	}
	public void setLogin(String login) {
		this.login = login;
	}
	
	@OneToOne(cascade = CascadeType.ALL)
    @PrimaryKeyJoinColumn
	private User user;
	
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	public String getShortName() {
		if (getUser() != null)
			return getUser().getShortName();
		return "";
	}
	public boolean equals(Object other) {
        return other instanceof Administrator  ? getUser().getLogin().equals(((Administrator) other).getUser().getLogin()) : false;
    }
    public int hashCode() {
        return getUser().getLogin().hashCode();
    }
    public String toString() {
		return getShortName();
	}
}
